
********************
****The following do file recodes relevant variables and 
****replicates the results reported in:
****Enns, Peter K. and Ashley Jardina. 2021. 
****"Complicating the Role of White Racial Attitudes and Anti-Immigrant Sentiment 
****in the 2016 US Presidential Election" Public Opinion Quarterly.
*****https://doi.org/10.1093/poq/nfab040
*********************

use "Economist-Recontact-Survey_OnlyVarsUsedInPOQarticle.dta", clear

*********************************************
**Recode BLM and isolated incident questions
*********************************************
gen opposeblm_w5 = .
recode opposeblm_w5 .=1 if blmsup_w5==1
recode opposeblm_w5 .=2 if blmsup_w5==2
recode opposeblm_w5 .=3 if blmsup_w5==5
recode opposeblm_w5 .=4 if blmsup_w5==3
recode opposeblm_w5 .=5 if blmsup_w5==4

gen opposeblm_w13 = .
recode opposeblm_w13 .=1 if suptblm_w13==1
recode opposeblm_w13 .=2 if suptblm_w13==2
recode opposeblm_w13 .=3 if suptblm_w13==3
recode opposeblm_w13 .=3 if suptblm_w13==6
recode opposeblm_w13 .=4 if suptblm_w13==4
recode opposeblm_w13 .=5 if suptblm_w13==5

label define blmlbl 1 "1 strongly support/approve" 2 "2 somewhat support/approve" 3 "3 neutral/not sure/haven't heard" 4 "4 somewhat oppose/disapprove" 5 "5 strongly oppose/disapprove"
label values opposeblm_w5 opposeblm_w13 blmlbl

gen isolatedinc_w5 = .
recode isolatedinc_w5 .=1 if blkcop_w5==2
recode isolatedinc_w5 .=2 if blkcop_w5==3
recode isolatedinc_w5 .=3 if blkcop_w5==1

gen isolatedinc_w13 = .
recode isolatedinc_w13 .=1 if blmpattern_w13==2
recode isolatedinc_w13 .=2 if blmpattern_w13==3
recode isolatedinc_w13 .=3 if blmpattern_w13==1

label define isolbl 1 "1 part of larger pattern" 2 "2 Not sure" 3 "isolated incidents"
label values isolatedinc_w5 isolatedinc_w13 isolbl


*********************************************
**Generate Clinton/Trump Vote Intention/Vote
*********************************************
gen presvote_w2 = hrcvstmp_w2
gen presvote_w6 = hcvdt2_w6
gen presvote_w11 = presvote16_w11
gen presvote_w13 = presvote16_w13
gen presvote_w15 = presvote16_w15
gen presvote_w16 = presvote16x_post

foreach i of numlist 2 6 11 13 15 16 {
gen trumpvote_w`i' = .
recode trumpvote_w`i' .=0 if presvote_w`i'==1
recode trumpvote_w`i' .=1 if presvote_w`i'==2
}
label define trumpvotelbl 0 "0 Clinton" 1 "1 Trump"
label values trumpvote* trumpvotelbl


*********************************************************************************
*********************************************************************************
**Figure 1A: Republican/Trump Support if Strongly Oppose BLM in W5 & W13
**Wave 6 (closest to Wave 5 measure of BLM sumpport,
**and Wave 13 to match measure of BLM support
**For those who strongly oppose BLM in wave 5 (Jan. 2016) and wave 13 (Aug. 2016)
svyset [pweight=weight_w1]
svy: tab vote_generic if race4==100 & opposeblm_w5==5 & opposeblm_w13==5, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w6]
svy: tab hcvdt2_w6 if race_w6==1 & opposeblm_w5==5 & opposeblm_w13==5, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab presvote16_w13 if race_w13==1 & opposeblm_w5==5 & opposeblm_w13==5, ci perc stubw(20) format(%2.1f)


*Figure 1B: Police killings isolated incident
svyset [pweight=weight_w1]
svy: tab vote_generic if race4==100 & isolatedinc_w5==3 & isolatedinc_w13==3, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w6]
svy: tab hcvdt2_w6 if race_w6==1 & isolatedinc_w5==3 & isolatedinc_w13==3, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab presvote16_w13 if race_w13==1 & isolatedinc_w5==3 & isolatedinc_w13==3, ci perc stubw(20) format(%2.1f)
*********************************************************************************
*********************************************************************************

*****************************************************************************
*****************************************************************************
**Figure 2: wave 5 (Jan. 2016) and wave 13 (Aug. 2016)
**For thsoe who supported Trump in both waves, did strong opposition to BLM
**increase as would be expected from the priming hypothesis?
**Using these surveys because they most closely match trump support with BLM measures

*2A: Trump Vote
svyset [pweight=weight_w5]
svy: tab opposeblm_w5 if race_w5==1 & trumpvote_w6==1 & trumpvote_w13==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab opposeblm_w13 if race_w13==1 & trumpvote_w6==1 & trumpvote_w13==1, ci perc stubw(20) format(%2.1f)

*2B: Clinton Vote
svyset [pweight=weight_w5]
svy: tab opposeblm_w5 if race_w5==1 & trumpvote_w6==0 & trumpvote_w13==0, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab opposeblm_w13 if race_w13==1 & trumpvote_w6==0 & trumpvote_w13==0, ci perc stubw(20) format(%2.1f)

****How about police killings?
*2C: Trump Vote
svyset [pweight=weight_w5]
svy: tab isolatedinc_w5 if race_w5==1 & trumpvote_w6==1 & trumpvote_w13==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab isolatedinc_w13 if race_w13==1 & trumpvote_w6==1 & trumpvote_w13==1, ci perc stubw(20) format(%2.1f)

*2D: Clinton Vote
svyset [pweight=weight_w5]
svy: tab isolatedinc_w5 if race_w5==1 & trumpvote_w6==0 & trumpvote_w13==0, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab isolatedinc_w13 if race_w13==1 & trumpvote_w6==0 & trumpvote_w13==0, ci perc stubw(20) format(%2.1f)
*****************************************************************************
*****************************************************************************




**Rescale ordinal variables to range from 0-1, recode don't know pid and ideo as dummies
 ssc install _gstd01.pkg
 
egen opposeblm_w5_01 = std01(opposeblm_w5)
egen opposeblm_w13_01 = std01(opposeblm_w13) 
egen isolatedinc_w5_01 = std01(isolatedinc_w5)
egen isolatedinc_w13_01 = std01(isolatedinc_w13)
clonevar pid7_w6_NS_ind = pid7_w6
recode pid7_w6_NS_ind 8=4
egen pid7_w6_NS_ind_01 = std01(pid7_w6_NS_ind)
clonevar ideo5_w6_NS_mod = ideo5_w6
recode  ideo5_w6_NS_mod 6=3
egen ideo5_w6_NS_mod_01 = std01(ideo5_w6_NS_mod)



******************************************************************************
**Table 1
*trumpvote_w6
**BLM opposition as a function of past Trump vote intention
svyset [pweight=weight_w13]
svy: ologit opposeblm_w13_01 i.hcvdt2_w6 opposeblm_w5_01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w13==1
**Police Killing views as a function of past Trump vote intention
svyset [pweight=weight_w13]
svy: ologit isolatedinc_w13_01 i.hcvdt2_w6 isolatedinc_w5_01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w13==1

**Trump vote in tention as function of:
**past BLM opposition
svyset [pweight=weight_w13]
svy: logit trumpvote_w13 i.hcvdt2_w6 opposeblm_w5_01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w13==1
**past views on police killings
svyset [pweight=weight_w13]
svy: logit trumpvote_w13 i.hcvdt2_w6 isolatedinc_w5 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w13==1
******************************************************************************


****************
****************
***Immigration
****************
****************

**Recode variables
gen brdrwall_w6ord =.
recode brdrwall_w6ord .=1 if brdrwall_w6==2
recode brdrwall_w6ord .=2 if brdrwall_w6==3
recode brdrwall_w6ord .=3 if brdrwall_w6==1

gen brdrwall_w11ord = .
recode brdrwall_w11ord .=1 if brdrwall_w11==2
recode brdrwall_w11ord .=2 if brdrwall_w11==3
recode brdrwall_w11ord .=3 if brdrwall_w11==1

gen brdrwall_w15ord = .
recode brdrwall_w15ord .=1 if borderwall_w15==2
recode brdrwall_w15ord .=2 if borderwall_w15==3
recode brdrwall_w15ord .=3 if borderwall_w15==1

gen immhurt_w12= immhelp_w12
recode immhurt_w12 (2=3) (3=2)

gen undocleav_w15 = illegalimm_w15
recode undocleav_w15 (2=3) (3=2) 

*********************************************************************************
**Figure 3: Republican/Trump Support among those with anti-immigrant attitudes
**3A: Trump Vote / Favor Border Wall
svyset [pweight=weight_w1]
svy: tab vote_generic if race4==100 & brdrwall_w6==1 & borderwall_w15==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w6]
svy: tab hcvdt2_w6 if race_w6==1 & brdrwall_w6==1 & borderwall_w15==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w15]
svy: tab presvote16_w15 if race_w15==1 & brdrwall_w6==1 & borderwall_w15==1, ci perc stubw(20) format(%2.1f)

**3B: Trump Vote / Immigration
svyset [pweight=weight_w1]
svy: tab vote_generic if race4==100 & immigration_w3==3 & immigration_w11==3, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w2]
svy: tab hrcvstmp_w2 if race_w2==1 & immigration_w3==3 & immigration_w11==3, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w13]
svy: tab presvote16_w13 if race_w13==1 & immigration_w3==3 & immigration_w11==3, ci perc stubw(20) format(%2.1f)
*********************************************************************************



**********
**Figure 4
***********
**Did Immigration Attitudes shift?
*Consider dropping unsure option for border wall question
*4A: Support border wall if consistent Trump vote intention
svyset [pweight=weight_w6]
svy: tab brdrwall_w6 if trumpvote_w6==1 & trumpvote_w15==1 & race_w6==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w15]
svy: tab borderwall_w15 if trumpvote_w6==1 & trumpvote_w15==1 & race_w15==1, ci perc stubw(20) format(%2.1f)
*4B: Support border wall if consistent Clinton vote intention
svyset [pweight=weight_w6]
svy: tab brdrwall_w6 if trumpvote_w6==0 & trumpvote_w15==0 & race_w6==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w15]
svy: tab borderwall_w15 if trumpvote_w6==0 & trumpvote_w15==0 & race_w15==1, ci perc stubw(20) format(%2.1f)

*4C: Immigrants must leave if consistent Trump vote intention
*Need to use trumpvote_w2 because not asked in w3, 4 or 5.
svyset [pweight=weight_w3]
svy: tab immigration_w3 if trumpvote_w2==1 & trumpvote_w11==1 & race_w3==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w11]
svy: tab immigration_w11 if trumpvote_w2==1 & trumpvote_w11==1 & race_w11==1, ci perc stubw(20) format(%2.1f)
*4D: Immigrants must leave if consistent Clinton vote intention
svyset [pweight=weight_w3]
svy: tab immigration_w3 if trumpvote_w2==0 & trumpvote_w11==0 & race_w3==1, ci perc stubw(20) format(%2.1f)
svyset [pweight=weight_w11]
svy: tab immigration_w11 if trumpvote_w2==0 & trumpvote_w11==0 & race_w11==1, ci perc stubw(20) format(%2.1f)
*********************************************************************************


************************
**Immigration, LDV Analysis
**Recode Variables

egen brdrwall_w6ord_01 = std01(brdrwall_w6ord)
egen brdrwall_w15ord_01 = std01(brdrwall_w15ord)

egen immigration_w3_01 = std01(immigration_w3)
egen immigration_w11_01 = std01(immigration_w11)

gen pid7_w3_NS_ind = .
recode pid7_w3_NS_ind .=1 if pid7_w3 ==1
recode pid7_w3_NS_ind .=2 if pid7_w3 ==2
recode pid7_w3_NS_ind .=3 if pid7_w3 ==5
recode pid7_w3_NS_ind .=4 if pid7_w3 ==7
recode pid7_w3_NS_ind .=5 if pid7_w3 ==6
recode pid7_w3_NS_ind .=6 if pid7_w3 ==4
recode pid7_w3_NS_ind .=7 if pid7_w3 ==3
recode pid7_w3_NS_ind .=4 if pid7_w3 ==8
egen pid7_w3_NS_ind_01 = std01(pid7_w3_NS_ind)

clonevar ideo5_w3_NS_mod = ideo5_w3
recode  ideo5_w3_NS_mod 6=3
egen ideo5_w3_NS_mod_01 = std01(ideo5_w3_NS_mod)

clonevar hrcvstmp_w2_rec = hrcvstmp_w2 
recode hrcvstmp_w2_rec (4=3)

*********************************************************************************
**Table 2
svyset [pweight=weight_w15]
svy: ologit brdrwall_w15ord_01 i.hcvdt2_w6 brdrwall_w6ord_01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w15==1
svyset [pweight=weight_w11]
svy: ologit immigration_w11_01 i.hrcvstmp_w2_rec immigration_w3_01 pid7_w3_NS_ind_01 ideo5_w3_NS_mod_01 if race_w11==1

svyset [pweight=weight_w15]
svy: logit trumpvote_w15 i.hcvdt2_w6 brdrwall_w6ord_01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w15==1
svyset [pweight=weight_w11]
svy: logit trumpvote_w11 i.hrcvstmp_w2_rec immigration_w3_01 pid7_w3_NS_ind_01 ideo5_w3_NS_mod_01 if race_w11==1
**************************************





**Post Election Vote Choice

*Footnote 13
**How accurate was final vote choice?
svyset [pweight=weight_post]
svy: tab presvote16x_post if presvote16x_post<4




*********************************************************************************
*Figure 5 - final vote choice
*********************************************************************************

*Demographic Vars
*Need to recode faminc_w6
*because 13 = Prefer not to say 
gen faminc_a = faminc_w6 if faminc_w6>=1 & faminc_w6<=11
gen faminc_b  = (faminc_w6-2) if faminc_w6>=14 & faminc_w6<=18
gen faminc_w6new = faminc_a 
replace faminc_w6new = faminc_b if faminc_w6new==.

egen faminc_w6_01 = std01(faminc_w6new)
*recode prefer not to say, so not dropped when we control for these responses
recode faminc_w6_01 .=-1 if faminc_w6==13
*recode ?$150K (not specific), so not dropped when we control for these responses
recode faminc_w6_01 .=-1 if faminc_w6==12
gen inc_dk = 0
recode inc_dk 0=1 if faminc_w6==13
gen inc_150 = 0
recode inc_150 0=1 if faminc_w6==12

gen unem_w6=0 if employstat2_w6!=.
recode unem_w6 0=1 if employstat2_w6==4
egen age_w6_01 = std01(age_w6)
egen educ_w6_01 = std01(educ_w6)
gen female_w6=0 if gender_w6 !=. 
recode female_w6 0=1 if gender_w6==2

*past vote intention
gen Clinton_w6=0 if hcvdt2_w6!=.
recode Clinton_w6 0=1 if hcvdt2_w6==1
gen Trump_w6=0 if hcvdt2_w6!=.
recode Trump_w6 0=1 if hcvdt2_w6==2
gen Other_w6=0 if hcvdt2_w6!=.
recode Other_w6 0=1 if hcvdt2_w6==3
gen NotVote_w6=0 if hcvdt2_w6!=.
recode NotVote_w6 0=1 if hcvdt2_w6==4



*gen race and immigration index variables
egen race_issues01 = rmean(opposeblm_w5_01 isolatedinc_w5_01)
egen immigration_w6_01 = std01(immigration_w6)
egen imm_issues01 = rmean(brdrwall_w6ord_01 immigration_w6_01)

egen race_issues01_w13 = rmean(opposeblm_w13_01 isolatedinc_w13_01)
egen imm_issues01_w11w15 = rmean(brdrwall_w15ord_01 immigration_w11_01)

*generate change in racial and immigration attitudes
gen d_race = race_issues01_w13-race_issues01
egen d_race01 = std01(d_race)
gen d_imm = imm_issues01_w11w15-imm_issues01
egen d_imm01 = std01(d_imm)

***
gen weight_w16=weight_post
svyset [pweight=weight_w16]
svy: logit trumpvote_w16 race_issues01 d_race01 imm_issues01 d_imm01 Trump_w6 Other_w6 NotVote_w6 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 educ_w6_01 faminc_w6_01 inc_dk inc_150 unem_w6 age_w6_01 female_w6 if race_post==1
foreach x in race_issues01 d_race01 imm_issues01 d_imm01 Trump_w6 Other_w6 NotVote_w6 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 educ_w6_01 unem_w6 age_w6_01 female_w6 {
quietly sum `x'
quietly local min = `r(min)'
quietly local max = `r(max)'
*family income mean needs to be calculated without the value for don't know (coded as -1).
quietly prvalue, x(`x'=`min' faminc_w6_01==.3806292) rest(mean) save
quietly prvalue, x(`x'=`max' faminc_w6_01==.3806292) rest(mean) diff
mat l r(pred)
}

/*
foreach x in race_issues01 d_race01 imm_issues01 d_imm01 Trump_w6 Other_w6 NotVote_w6 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 educ_w6_01 unem_w6 age_w6_01 female_w6 {
quietly sum `x'
quietly local min = `r(min)'
quietly local max = `r(max)'
*family income mean needs to be calculated without the value for don't know (coded as -1).
margins, at(`x'=`min' `x'=`max' faminc_w6_01==.3806292) atmeans 
}
*/


*Don't know and income>$150K need to be calculated w/o family income set to specific value
foreach x in faminc_w6_01 inc_dk inc_150 {
quietly sum `x'
quietly local min = `r(min)'
quietly local max = `r(max)'
quietly prvalue, x(`x'=`min') rest(mean) save
quietly prvalue, x(`x'=`max') rest(mean) diff
mat l r(pred)
}
*********************************************************************************
*********************************************************************************

***************************************************
***************************************************
****Supplementary/Online Materials
***************************************************
***************************************************

************
**Section 1
************

**Wave 13 asked 8 questions that measure black racial resentment
clonevar blklessdes = raceresent_1b_w13
gen overcameprej = raceresent_2b_w13
recode overcameprej (1=5) (5=1) (2=4) (4=2)
gen tryhard = raceresent_3b_w13
recode tryhard (1=5) (5=1) (2=4) (4=2)
clonevar slavery = raceresent_4b_w13
gen affact = afirmact_w13
recode affact (2=3) (3=2)
gen marriage = miscegeny_w13
recode marriage (2=3) (3=2)

*Cronbach's alpha
alpha opposeblm_w13 blklessdes overcameprej slavery tryhard isolatedinc_w13 affact marriage

**Table A-1
factor opposeblm_w13 blklessdes overcameprej slavery tryhard isolatedinc_w13 affact marriage

************
**Section 2
************

*Cronbach's alpha
alpha immigration_w11 brdrwall_w11ord immhurt_w12 undocleav_w15

*Table A-2
factor immigration_w11 brdrwall_w11ord immhurt_w12 undocleav_w15

************
**Section 4
************

*Table A-3
**BLM opposition as a function of past Trump vote intention
svyset [pweight=weight_w13]
svy: ologit opposeblm_w13_01 i.hcvdt2_w6 opposeblm_w5_01 i.pid7_w6 i.ideo5_w6 if race_w13==1
**Police Killing views as a function of past Trump vote intention
svyset [pweight=weight_w13]
svy: ologit isolatedinc_w13_01 i.hcvdt2_w6 isolatedinc_w5_01 i.pid7_w6 i.ideo5_w6 if race_w13==1

**Trump vote in tention as function of:
**past BLM opposition
svyset [pweight=weight_w13]
svy: logit trumpvote_w13 i.hcvdt2_w6 opposeblm_w5_01 i.pid7_w6 i.ideo5_w6 if race_w13==1
**past views on police killings
svyset [pweight=weight_w13]
svy: logit trumpvote_w13 i.hcvdt2_w6 isolatedinc_w5 i.pid7_w6 i.ideo5_w6 if race_w13==1


*Table A-4
***IMMIGRATION
svyset [pweight=weight_w15]
svy: ologit brdrwall_w15ord_01 i.hcvdt2_w6 brdrwall_w6ord_01 I.pid7_w6 I.ideo5_w6 if race_w15==1
svyset [pweight=weight_w11]
svy: ologit immigration_w11_01 i.hrcvstmp_w2_rec immigration_w3_01 I.pid7_w3 I.ideo5_w3 if race_w11==1


svyset [pweight=weight_w15]
svy: logit trumpvote_w15 i.hcvdt2_w6 brdrwall_w6ord_01 I.pid7_w6 I.ideo5_w6 if race_w15==1
svyset [pweight=weight_w11]
svy: logit trumpvote_w11 i.hrcvstmp_w2_rec immigration_w3_01 I.pid7_w3 I.ideo5_w3 if race_w11==1


************
**Section 5
************

*Table A-5
*Do Clinton supporters decrease support for border wall as implied by Figure 4b
svyset [pweight=weight_w15]
svy: ologit brdrwall_w15ord_01 Clinton_w6 Trump_w6 brdrwall_w6ord_01 if race_w15==1

************
**Section 6
************

*Table A-6
**Replicate Results with Index Variables used for final vote choice analysis
svyset [pweight=weight_w13]
svy: reg race_issues01_w13 i.hcvdt2_w6 race_issues01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w13==1
svy: logit trumpvote_w13 i.hcvdt2_w6 race_issues01 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 if race_w13==1
******************

************
**Section 7
************

*Table A-7
svyset [pweight=weight_w16]
svy: logit trumpvote_w16 race_issues01 d_race01 imm_issues01 d_imm01 Trump_w6 Other_w6 NotVote_w6 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 educ_w6_01 faminc_w6_01 inc_dk inc_150 unem_w6 age_w6_01 female_w6 if race_post==1

************
**Section 8
************

*Table A-8
*Heckman test for selection


*Identify who was in w6 (first panel in Fig 5 analysis)
*but not the post-election survey
gen attrition=1 if weight_w6!=.
recode attrition 1=0 if weight_post==.
***
heckman trumpvote_w16 race_issues01 d_race01 imm_issues01 d_imm01 Trump_w6 ///
Other_w6 NotVote_w6 pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 educ_w6_01 faminc_w6_01 ///
inc_dk unem_w6 age_w6_01 female_w6 if race_post==1, ///
select (attrition = pid7_w6_NS_ind_01 ideo5_w6_NS_mod_01 educ_w6_01 faminc_w6_01 ///
inc_dk unem_w6 age_w6_01 female_w6 i.region_w6) twostep
************************

















